package com.union.core.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.union.core.dao.IParamDao;
import com.union.core.dao.impl.ParamDaoImpl;
import com.union.core.model.Param;

public class ParamService {
	private static ParamService instance;
	private IParamDao paramDao;

	public ParamService() {
		paramDao = new ParamDaoImpl();
	}

	public Map<String, Object> getAllParamType(){
		Map<String, Object> result = new HashMap<String, Object>();

		List<Param> paramList = paramDao.queryList();
		if(paramList == null || paramList.size() == 0){
			return result;
		}
		
		String paramType = "";
		String newParamType = "";
		List<Param> tmpList = null;
		for(int i = 0;i!=paramList.size();++i){
			Param param = paramList.get(i);
			newParamType = param.getParamType();
			if(!newParamType.equals(paramType)){
				if(tmpList!=null){
					result.put("param" + paramType, tmpList);
				}
				tmpList = new ArrayList<Param>();
				paramType = newParamType;
			}
			tmpList.add(param);
			if((i+1) == paramList.size()){
				result.put("param" + newParamType, tmpList);
			}
		}
		return result;
	}

	/**
	 * @return the instance
	 */
	public static ParamService getInstance() {
		if(instance == null){
			instance = new ParamService();
		}
		return instance;
	}
}
